package io.renren.sf.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.renren.common.utils.R;
import io.renren.sf.entity.TeacherInstructionEntity;
import io.renren.sf.service.TeacherInstructionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;


/**
 * @author cyl_txw
 * @email cyl_txw@gmail.com
 * @date 2023-03-26 22:21:11
 */
@RestController
@RequestMapping("sf/teacherInstruction")
@Api(tags = "教师使用说明书管理")
@ApiIgnore
public class TeacherInstructionController {
    @Autowired
    private TeacherInstructionService teacherInstructionService;

    /**
     * 说明书分页
     */
    @ApiOperation("分页查看说明书列表")
    @GetMapping("/list")
    public R pcsystemEditionPage(@RequestParam Map<String, Object> params) {
        long page = Long.parseLong((String) params.get("page"));
        long limit = Long.parseLong((String) params.get("limit"));
        Page<TeacherInstructionEntity> teacherInstructionPage = new Page<>(page, limit);
        teacherInstructionService.page(teacherInstructionPage);
        return R.ok().put("teacherInstructionPage", teacherInstructionPage);
    }
    /**
     * 信息
     */
    @ApiOperation("根据id查找说明书")
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
        TeacherInstructionEntity teacherInstructionEntity = teacherInstructionService.getById(id);

        return R.ok().put("teacherInstruction", teacherInstructionEntity);
    }

    /**
     * 保存
     */
    @ApiOperation("保存说明书")
    @PostMapping("/save")
    public R save(@RequestBody TeacherInstructionEntity teacherInstructionEntity){
        teacherInstructionEntity.setCreatetime(new Date());
        teacherInstructionService.save(teacherInstructionEntity);
        return R.ok();
    }

    /**
     * 修改
     */
    @ApiOperation("修改说明书")
    @PostMapping("/update")
    public R update(@RequestBody TeacherInstructionEntity teacherInstructionEntity){
        teacherInstructionService.updateById(teacherInstructionEntity);

        return R.ok();
    }

    /**
     * 删除
     */
    @ApiOperation("根据说明书id列表删除")
    @PostMapping("/delete")
    public R delete(@RequestBody Long[] ids){
        teacherInstructionService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

}
